using System;
using System.Collections;

namespace InfoJetSoft.Service.Util
{

	class StringTokenizer 
	{
		private ArrayList tokenList = new ArrayList();
		private int index;
  
		public StringTokenizer(string dataLine) {
			init(dataLine," ");
		}

		public StringTokenizer(string data,string delim) {
			init(data,delim);
		}

		private void init(string data ,String delim) {
			int delLength = delim.Length;
			int pos = data.IndexOf( delim , 0 );

			while( pos >= 0 ){
				string token = data.Substring( 0 , pos );
				tokenList.Add( token );
				data = data.Substring( pos + delLength );
				pos = data.IndexOf( delim , 0 );
			}
			tokenList.Add( data );
			
			if( tokenList.Count >= 2 ){
				if( ((string)tokenList[ 0 ]).Length <= 0 ){
					tokenList.RemoveAt( 0 );
				}
				if( ((string)tokenList[ tokenList.Count - 1 ]).Length <= 0 ){
					tokenList.RemoveAt( tokenList.Count - 1 );
				}
			}

			index = 0;
		}
  
		public bool HasMoreElements() {
			return (index < (tokenList.Count));
		}

		public string NextElement() {
			if(index < tokenList.Count)
				return (string)tokenList[index++];
			else
				return null;
		}

		public bool HasMoreTokens() {
			return (index < (tokenList.Count));
		}

		public string NextToken() {
			if(index < tokenList.Count)
				return (string)tokenList[index++];
			else
				return null;
		}

		public int Count {
			get {
				return tokenList.Count;
			}
			
		}

	}
 

}
